import resolver

from calc_core.gradient_strategy import gradient_strategy
from calc_core.gradient_strategy_diff import gradient_strategy_diff
from calc_core.core import CalcCore
from calc_core.preprocessor import PreProcessor
from calc_core.preprocessor_plugin import select_person, extract_designative_key_points, smooth_key_points

BASE_VIDEO_NAME = "video1"
BASE_VIDEO_URL = "./json_results"
USER_VIDEO_NAME = "video3"
USER_VIDEO_URL = "./json_results"


def main():
    base_frames = resolver.get_video_key_points(BASE_VIDEO_URL, BASE_VIDEO_NAME)
    user_frames = resolver.get_video_key_points(USER_VIDEO_URL, USER_VIDEO_NAME)
    # print(json.dumps(user_frames[0], default=lambda o: o.__dict__, sort_keys=True, indent=4))
    # 初始化预处理器
    preProcessor1 = PreProcessor()
    preProcessor1.insert_processor(select_person, {"person_code": 0})
    preProcessor1.insert_processor(extract_designative_key_points,
                                   {"key_points_indexes": "all", "show_bbox": False})
    # preProcessor1.insert_processor(smooth_key_points, {"EM_num": 10})
    preProcessor2 = PreProcessor()
    preProcessor2.insert_processor(select_person, {"person_code": 0})
    preProcessor2.insert_processor(extract_designative_key_points,
                                   {"key_points_indexes": "all", "show_bbox": False})
    # preProcessor2.insert_processor(smooth_key_points, {"EM_num": 10})
    print("base视频开始预处理")
    base_frames = preProcessor1.do(base_frames)
    print("base视频开始预处理结束")
    print("user视频开始预处理")
    user_frames = preProcessor2.do(user_frames)
    print("user视频预处理结束")
    # 创建算分实例
    print("开始算分流程")
    calc_core = CalcCore(base_input=base_frames, user_input=user_frames, sync_strategy=gradient_strategy, strategy=gradient_strategy_diff)
    print("经计算，视频{}的舞蹈稳定度得分为{}分".format(USER_VIDEO_NAME, ((1 - calc_core.calc_score(gradient_strategy) * 5) * 100)))
    print("经计算，视频{}的舞蹈精准度得分为{}分".format(USER_VIDEO_NAME, 100 - calc_core.calc_score(gradient_strategy_diff)))


# 程序在这里运行
if __name__ == '__main__':
    main()
